package com.ruoyi.service.impl;

import java.util.List;

import com.ruoyi.domain.*;
import com.ruoyi.mapper.*;
import com.ruoyi.system.domain.ZhwyShops;
import com.ruoyi.system.mapper.ZhwyShopsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.service.IZhwyCashregisterService;

/**
 * 综合收银Service业务层处理
 *
 * @author ruoyi
 * @date 2024-05-08
 */
@Service
public class ZhwyCashregisterServiceImpl implements IZhwyCashregisterService {
    @Autowired
    private ZhwyCashregisterMapper zhwyCashregisterMapper;

    @Autowired
    private ZhwyShopsMapper zhwyShopsMapper;
    @Autowired
    private ZhwyHirerMapper zhwyHirerMapper;
    @Autowired
    private ZhwyRentalcontractMapper zhwyRentalcontractMapper;
    @Autowired
    private ZhwyChargedataMapper zhwyChargedataMapper;
    @Autowired
    private ZhwyChargeitemMapper zhwyChargeitemMapper;

    @Autowired
    private ZhwyTemporarydepositMapper zhwyTemporarydepositMapper;


    /**
     * 查询综合收银
     *
     * @param id 综合收银主键
     * @return 综合收银
     */
    @Override
    public ZhwyCashregister selectZhwyCashregisterById(Long id) {
        return zhwyCashregisterMapper.selectZhwyCashregisterById(id);
    }

    /**
     * 查询综合收银列表
     *
     * @param zhwyCashregister 综合收银
     * @return 综合收银
     */
    @Override
    public List<ZhwyCashregister> selectZhwyCashregisterList(ZhwyCashregister zhwyCashregister) {
        List<ZhwyCashregister> list = zhwyCashregisterMapper.selectZhwyCashregisterList(zhwyCashregister);
//        System.out.println(zhwyCashregister);
        if (zhwyCashregister.getCode() != null && !"".equals(zhwyCashregister.getCode())) {
            ZhwyShops zhwyShops = new ZhwyShops();
            zhwyShops.setCode(zhwyCashregister.getCode());
            List<ZhwyShops> zhwyShopsList = zhwyShopsMapper.selectZhwyShopsList(zhwyShops);
            ZhwyShops shops = zhwyShopsList.get(0);


            ZhwyRentalcontract zhwyRentalcontract = new ZhwyRentalcontract();
            zhwyRentalcontract.setShopsId(shops.getId());
            List<ZhwyRentalcontract> zhwyRentalcontractList = zhwyRentalcontractMapper.selectZhwyRentalcontractList(zhwyRentalcontract);
            ZhwyRentalcontract rentalContract = zhwyRentalcontractList.get(0);

            ZhwyHirer zhwyHirer1 = new ZhwyHirer();
            zhwyHirer1.setId(rentalContract.getHirerId());
            List<ZhwyHirer> zhwyHirerList = zhwyHirerMapper.selectZhwyHirerList(zhwyHirer1);
            ZhwyHirer zhwyHirer = zhwyHirerList.get(0);

            //常规收费表格
            ZhwyChargedata zhwyChargedata1 = new ZhwyChargedata();
            zhwyChargedata1.setShopsId(shops.getId());
            List<ZhwyChargedata> zhwyChargedataList = zhwyChargedataMapper.selectZhwyChargedataList(zhwyChargedata1);
            ZhwyChargedata zhwyChargedata = zhwyChargedataList.get(0);

            ZhwyChargeitem zhwyChargeitem1 = new ZhwyChargeitem();
            zhwyChargeitem1.setId(zhwyChargedata1.getChargeItemId());
            List<ZhwyChargeitem> zhwyChargeitemList = zhwyChargeitemMapper.selectZhwyChargeitemList(zhwyChargeitem1);
            ZhwyChargeitem zhwyChargeitem = zhwyChargeitemList.get(0);

            //临时收费/押金管理表格
            ZhwyTemporarydeposit zhwyTemporarydeposit = new ZhwyTemporarydeposit();
            zhwyTemporarydeposit.setShopsId(shops.getId());
            List<ZhwyTemporarydeposit> zhwyTemporarydepositList = zhwyTemporarydepositMapper.selectZhwyTemporarydepositList(zhwyTemporarydeposit);


            //相关信息
            list.get(0).setCode(zhwyCashregister.getCode());
            list.get(0).setZhwyShops(shops);
            list.get(0).setZhwyRentalcontract(rentalContract);
            list.get(0).setZhwyHirer(zhwyHirer);
            //常规收费表格
            list.get(0).setZhwyChargedata(zhwyChargedata);
            list.get(0).setZhwyChargeitem(zhwyChargeitem);
            //临时收费/押金管理表格
            list.get(0).setZhwyTemporarydepositList(zhwyTemporarydepositList);
            System.out.println("====：" + list);
        }


        return list;
    }

    /**
     * 新增综合收银
     *
     * @param zhwyCashregister 综合收银
     * @return 结果
     */
    @Override
    public int insertZhwyCashregister(ZhwyCashregister zhwyCashregister) {
        return zhwyCashregisterMapper.insertZhwyCashregister(zhwyCashregister);
    }

    /**
     * 修改综合收银
     *
     * @param zhwyCashregister 综合收银
     * @return 结果
     */
    @Override
    public int updateZhwyCashregister(ZhwyCashregister zhwyCashregister) {
        return zhwyCashregisterMapper.updateZhwyCashregister(zhwyCashregister);
    }

    /**
     * 批量删除综合收银
     *
     * @param ids 需要删除的综合收银主键
     * @return 结果
     */
    @Override
    public int deleteZhwyCashregisterByIds(Long[] ids) {
        return zhwyCashregisterMapper.deleteZhwyCashregisterByIds(ids);
    }

    /**
     * 删除综合收银信息
     *
     * @param id 综合收银主键
     * @return 结果
     */
    @Override
    public int deleteZhwyCashregisterById(Long id) {
        return zhwyCashregisterMapper.deleteZhwyCashregisterById(id);
    }
}
